package tech.aistar.corejava.test.thread;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * @author success
 * @version 1.0
 * @description:本类用来演示:创建一个定长线程池，支持定时及周期性任务执行
 * @date 2019/8/2 0002
 */
public class ThreadPoolExecutorTest03 {
    public static void main(String[] args) {
        ScheduledExecutorService executorService =  Executors.newScheduledThreadPool(5);

//        executorService.schedule(new Runnable() {
//            @Override
//            public void run() {
//                System.out.println("延迟1秒后执行");
//            }
//        },1, TimeUnit.SECONDS);
        executorService.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                System.out.println("延迟1秒后执行");
            }
            //延迟一秒,每过三秒执行一次
        },1, 3,TimeUnit.SECONDS);
    }
}
